#include <iostream>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>

using namespace std;

#ifndef _SOCKBASE_H_
#define _SOCKBASE_H_

//the maximum length of the queue of pending connections
const int max_listen_backlog = 3;

class SockBase{
	public:
		SockBase();
		~SockBase();

		/* create socket descriptor */	
		virtual bool Socket()=0;

		/* build connection */
		bool Bind();
		bool Connect();	
		bool Listen(int backlog=max_listen_backlog);	
		int Accept();

		/* message communication */
		ssize_t Send(const void *buf,size_t len);
		ssize_t Receive(void *buf,size_t len);
		
		string GetErr(){
			return errMessage;	
		}
		
	private:
		void Err(){
			errMessage = strerror(errno);
		}
		
	private:
		string errMessage;

};

#endif
